// pages/result/result.js
Page({
  data: {
  calDate:"",
  //适用税率
  rate:"",
  //速算扣除数
  susuanKouchu:"",
  //累计应纳税额
  taxAccount:"",
  //本月应纳税额
  taxMonth:"",
  //税后工资
  salaryAfter:'0.00',
  //累计应纳税额
  LeijiYingNaShuiE:'',
  // 循环显示每个月的应交个税
  taxForEachMonth:[],
  //社保个人缴纳比例
  monthBox:[],
  sbRate:[0,0.1,0.102,0.105,0.106],
  //公积金个人缴纳比例
  gjjRate:[0,0.05,0.06,0.07,0.08,0.09,0.1,0.11,0.12,0.2],
  salary:[],
  salaryEnd:[],
  salaryStart:[],
  eduDate:[],
  babyBirth:[],
  rentStart:[], 
  rentEnd:[], 
  rentType:[], 
  childEduRatio:0.5,
	furtherEduChoice:{yes:false,no:true},
  degreeRuXueDate:"请选择入学时间",
  elderDate:"请选择老人何时年满六十",
  loanNum:0,
  elderValue:0,
  degreeValue:"",
  babyCareRatio:0.5,
  graduateDate:"预计毕业时间",
  loanEndDate:"贷款还完时间",
  loanStartDate:"首次还款时间",
  eduGraduateDate:[],

  //计算结果存储变量,索引为月份-1，第1个存储结果为1月，第2个是1+2月的，第3个是1+2+3月的
  yingNashuiEAcc:[],
  eduAcc:[],
  loanAcc:[],
  furtherAcc:[],
  babyAcc:[],
  degreeAcc:[],
  elderAcc:[],
  rentAcc:[],
  salaryAcc:[],

  taxAcc:[],
  susuanAcc:[],
  rateAcc:[],

  //社保
  sbStandard:[],
  sbDaBingYL:[],
  sbIndex:[],
  sbEndDate:[],
  sbStartDate:[],

  //公积金
  gjjStart:[],
  gjjEnd:[],
  gjjStandard:[],
  gjjIndex:[],

  // 其他扣除
  anotherStart:[],
  anotherEnd:[],
  nianJin:[],
  bussinessHealth:[],
  yangLaoJin:[],
  other:[],
  },

  compareDate:function(dateStr1,dateStr2){
    const date1 = new Date(dateStr1);
    const date2 = new Date(dateStr2);
    if (date1 > date2) {
        return 1;
    } else if (date1 < date2) {
        return 2;
    } else {
        return 0;
    }
  },

  // 判断当前索引月份是否在当前时间区间内
  /**
   * 
   * @param {String} startStr 
   * @param {String} endStr 
   * @param {integer} monthIdx 
   */
  isMonthInThatDuration:function(startStr,endStr,monthIdx){
    var cal = this.data.calDate;
    var start = startStr;
    var end = endStr;
    if(start.indexOf("-") === -1 || end.indexOf("-") === -1){
      return false;
    }
    //结束年份小于纳税年份，返回为false
    if(Number(end.slice(0,4)) < Number(cal.slice(0,4))){
       return false;
    }
    // 结束年份等于或大于当前计算年份
    else{
      if(Number(start.slice(0,4)) < Number(cal.slice(0,4))){
        if(Number(end.slice(-2)) > monthIdx){
           return true;
        }
      }else if(Number(start.slice(0,4)) === Number(cal.slice(0,4))){
        if(Number(end.slice(-2)) >= monthIdx && Number(start.slice(-2)) <= monthIdx){
          return true;
       }
      }else;
    }
    return false;
  },

  /* 输入开始时间数组StrArry，结束时间数组StrArry，平摊比例(number)，每月扣除标准（number）四个参数
  *输出的结果是累计计算结果eduAcc。
  在累计计算结果中，eduAcc[0]存储的是1月专项累计扣除扣了多少钱，eduAcc[1]存储的是1+2月累计扣多少
  如果第i+1月不满足扣除条件，则eduAcc[i+1] = eduAcc[i]
  子女教育，婴幼儿可以用这个函数计算
  婴幼儿需要自行制作一个endArry,我自己为了方便我就制作一个数组每一项全部放calDate，计算出来结果是一样的
  */
  calArrayAcc:function(startArry,endArry,ratio,kouchuNumber){
    var eduStart = startArry;
    var eduEnd = endArry;
    var cal = this.data.calDate;
    var length = Number(cal.slice(-2));
    var eduAcc = [];
    var tempResult = 0;
    var ratio = ratio;
    var kouchu = kouchuNumber;
    for(var i = 1;i <= length;i++){
      for(var j = 0;j < eduStart.length;j++){ 
        if(this.isMonthInThatDuration(eduStart[j],eduEnd[j],i)){
          tempResult = tempResult + kouchu * ratio;
        }else{
          tempResult = tempResult + 0;
        }
      }
      eduAcc.push(tempResult);
    }
    return eduAcc;
  },

  /**
   * 计算房租比较特殊，随着扣除选项的改变，每个月的扣除数也是动态变化的，
   * 该函数只能给租房用
   */
  calRentAcc:function(){
    var eduStart = this.data.rentStart;
    var eduEnd = this.data.rentEnd;
    var cal = this.data.calDate;
    var length = Number(cal.slice(-2));
    var eduAcc = [];
    var tempResult = 0;
    var kouchu = this.data.rentType;
    for(var i = 1;i <= length;i++){
      for(var j = 0;j < kouchu.length;j++){ 
        if(this.isMonthInThatDuration(eduStart[j],eduEnd[j],i)){
          tempResult = tempResult + Number(kouchu[j]);
          //第i月已经计算，如果租房时间出现重叠，以第一次填写的为主，后面不算直接跳出循环。
          break;
        }else{
          tempResult = tempResult + 0;
        }
      }
      eduAcc.push(tempResult);
    }
    return eduAcc;  
  },

  /**
   * 
   * @param {String} startDate 开始日期
   * @param {String} endDate 结束日期，
   * @param {integer} kouchu 每月扣除数
   * 输出的结果是累计计算结果acc。
  在累计计算结果中，acc[0]存储的是1月专项累计扣除扣了多少钱，acc[1]存储的是1+2月累计扣多少
  如果第i+1月不满足扣除条件，则acc[i+1] = acc[i]
  可使用的扣除：首套贷，赡养老人，学历教育，
   */
  calDateAcc:function(startDate,endDate,kouchu){
    var start = startDate;
    var end = endDate;
    var cal = this.data.calDate;
    var length = Number(cal.slice(-2));
    var acc = [];
    var result = 0;
    for(var i = 1;i <= length;i++){
      if(this.isMonthInThatDuration(start,end,i)){
         result = result + kouchu
      }else{
        // 当月不满足条件，可扣除金额为0
        result = result + 0;
      }
      acc.push(result);
    }
    return acc;
  },
  
  // 继续教育在申报当月一次性扣除
  calFurtherAcc:function(){
    var cal = this.data.calDate;
    var furtherDate = this.data.furtherDate;
    var furtherEduChoice = this.data.furtherEduChoice;
    var length = Number(cal.slice(-2));
    var furtherAcc = []
    for(var i = 1;i <= length;i++){
      furtherAcc.push(0);
    }
    //如果本年已申报，把那个月的值改成3600
    if(furtherEduChoice.yes){
      var idx = Number(furtherDate.slice(-2));
      furtherAcc[idx - 1] = 3600
    }
    return furtherAcc;
  },
  /**
   * 计算累计工资，返回结果为eduAcc[]
   * 第i项存放的是第i+1月的累计收入
   */
  calSalaryAcc:function(){
    var eduStart = this.data.salaryStart;
    var eduEnd = this.data.salaryEnd;
    var cal = this.data.calDate;
    var length = Number(cal.slice(-2));
    var eduAcc = [];
    var tempResult = 0;
    var salary = this.data.salary;
    
    // 工资是有可能用户什么都不写的
    var temp = 0;
    for(var i = 1;i <= length;i++){
      for(var j = 0;j < eduStart.length;j++){ 
        if(this.isMonthInThatDuration(eduStart[j],eduEnd[j],i)){
          if(salary[j] !== ''){
            temp = Number(salary[j])
          }
          tempResult = tempResult + temp;
          //break;不会出现这个情况，已控制时间区间不能交叉
          //这里不允许多次匹配并累加，一个月不能有多个工资记录。
          temp = 0;
          break;
      }
    }
      eduAcc.push(tempResult);
    }
    this.setData({salayAcc:eduAcc});
    return eduAcc;
  },

  // 计算累计社保 社保基数 * 比例 + 大病医疗保险
  calSBAcc:function(){
    var eduStart = this.data.sbStartDate;
    var eduEnd = this.data.sbEndDate;
    var cal = this.data.calDate;
    var length = Number(cal.slice(-2));
    var eduAcc = [];
    var tempResult = 0;
    var ratio = this.data.sbRate;
    var kouchu = this.data.sbStandard;
    var index = this.data.sbIndex;
    var sbYiLiao = this.data.sbDaBingYL;
    for(var i = 1;i <= length;i++){
      for(var j = 0;j < eduStart.length;j++){ 
        if(this.isMonthInThatDuration(eduStart[j],eduEnd[j],i)){
          //社保只能交一个地方，当前月份按照第一个填写的内容进行扣除，后面写的不算
          tempResult = parseFloat(tempResult) + kouchu[j] * ratio[index[j]] + sbYiLiao[j];
          break;
        }else{
          tempResult = tempResult + 0;
        }
      }
      tempResult = parseFloat(tempResult).toFixed(2)
      eduAcc.push(tempResult);
    }
    return eduAcc;
  },

  // 公积金计算
  calGongjijinAcc:function(){
    var eduStart = this.data.gjjStart;
    var eduEnd = this.data.gjjEnd;
    var cal = this.data.calDate;
    var length = Number(cal.slice(-2));
    var eduAcc = [];
    var tempResult = 0;
    var idx = this.data.gjjIndex;
    var kouchu = this.data.gjjStandard;
    var ratio = this.data.gjjRate;
    for(var i = 1;i <= length;i++){
      for(var j = 0;j < eduStart.length;j++){ 
        if(this.isMonthInThatDuration(eduStart[j],eduEnd[j],i)){
          //公积金也只能交一份，按照首次填写的记录为准
          tempResult = parseFloat(tempResult) + kouchu[j] * ratio[idx[j]];
          break;
        }else{
          tempResult = tempResult + 0;
        }
      }
      tempResult = parseFloat(tempResult).toFixed(2)
      eduAcc.push(tempResult);
    }
    this.setData({})
    return eduAcc;
  },

  // 计算专项附加扣除累计
  calPersonAcc:function(){
    var babyEnd = [];
    var babyStart = this.data.babyBirth;
    var cal = this.data.calDate;
    for(var i = 0;i < babyStart.length;i++){
      babyEnd.push(cal);
    }
    var babyRatio = this.data.babyCareRatio;
    var childEduStart = this.data.eduDate;
    var childEduEnd = this.data.eduGraduateDate;
    var childEduRatio = this.data.childEduRatio;
    // 计算子女教育+婴幼儿专项附加扣除
    var BabyAcc = this.calArrayAcc(babyStart,babyEnd,babyRatio,2000);
    var childEduAcc = this.calArrayAcc(childEduStart,childEduEnd,childEduRatio,2000);
    // 计算赡养老人专项附加扣除
    var elderStart = this.data.elderDate;
    var elderKouchu = this.data.elderValue;
    var elderAcc = this.calDateAcc(elderStart,cal,elderKouchu);
    // 首套贷+学历教育
    var loanStartDate = this.data.loanStartDate;
    var loanEndDate = this.data.loanEndDate;
    var loanValue = this.data.loanNum;
    var loanAcc =  this.calDateAcc(loanStartDate,loanEndDate,Number(loanValue));
    var degreeStart = this.data.degreeRuXueDate;
    var degreeGraduate = this.data.graduateDate;
    var degreeValue = this.data.degreeValue;
    var degreeAcc = this.calDateAcc(degreeStart,degreeGraduate,Number(degreeValue));
    // 继续教育
    var furtherEdu = this.calFurtherAcc();
    // 租房
    var rentAcc = this.calRentAcc();
    console.log(rentAcc)
    var personAcc = [];
    var result = 0;
    for(var i = 0;i < furtherEdu.length;i++){
      result = furtherEdu[i] + degreeAcc[i] + rentAcc[i] + BabyAcc[i] + 
      loanAcc[i] + elderAcc[i] + childEduAcc[i];
      personAcc.push(result);
    }
    return personAcc;
  },

  // 计算累计其他扣除
  calAnotherAcc:function(){
    var eduStart = this.data.anotherStart;
    var eduEnd = this.data.anotherEnd;
    var cal = this.data.calDate;
    var length = Number(cal.slice(-2));
    var eduAcc = [];
    var tempResult = 0;
    var nianJin = this.data.nianJin;
    var bussinessHealth = this.data.bussinessHealth;
    var yangLaoJin = this.data.yangLaoJin;
    var other = this.data.other;
    var temp1 = 0,temp2 = 0,temp3 = 0,temp4 = 0;
    for(var i = 1;i <= length;i++){
      for(var j = 0;j < eduStart.length;j++){ 
        if(this.isMonthInThatDuration(eduStart[j],eduEnd[j],i)){
          if(nianJin[i] !== ''){
            temp1 = Number(nianJin[j]);
          }
          if(bussinessHealth[i] !== ''){
            temp2 = Number(bussinessHealth[j]);
          }
          if(yangLaoJin[i] !== ''){
            temp3 = Number(yangLaoJin[j]);
          }
          if(other[i] !== ''){
            temp4 = Number(other[j]);
          }
          //其他扣除每个月只能算一份，按照首次填写的记录为准
          tempResult = tempResult + temp1 + temp2 + temp3 + temp4;
          break;
        }else{
          tempResult = tempResult + 0;
        }
        temp1 = 0,temp2 = 0,temp3 = 0,temp4 = 0;
      }
      eduAcc.push(tempResult);
    }
    return eduAcc; 
  },

/**
 * 
 * @param {Number} salaryAcc 
 */
  getRateAndKouchu:function(salaryAcc){
    var tax = 0;
    var susuan = 0;
    var rateAcc = 0;
    var salary = parseFloat(salaryAcc);
    if(salary <= 36000){
      tax = (salary * 0.03).toFixed(2);
      susuan = '0';
      rateAcc = '3%';
      return {tax:tax,susuan:susuan,rateAcc:rateAcc};
    } if(salary > 36000 && salary <= 144000){
      tax = (salary * 0.1 - 2520).toFixed(2);
      susuan = '2520';
      rateAcc = '10%';
      return {tax:tax,susuan:susuan,rateAcc:rateAcc};
    } if(salary > 144000 && salary >= 300000){
      tax = (salary * 0.2 - 16920).toFixed(2);
      susuan ='16920';
      rateAcc = '20%';
      return {tax:tax,susuan:susuan,rateAcc:rateAcc};
    } if(salary > 300000 && salary <= 420000){
      tax = (salary * 0.25 - 31920).toFixed(2);
      susuan = '31920';
      rateAcc = '25%';
      return {tax:tax,susuan:susuan,rateAcc:rateAcc};
    } if(salary > 420000 && salary <= 660000){
      tax = (salary * 0.3 - 52920).toFixed(2);
      susuan = '52920';
      rateAcc = '30%';
      return {tax:tax,susuan:susuan,rateAcc:rateAcc};
    } if(salary > 660000 && salary <= 960000){
      tax = (salary * 0.35 - 85920).toFixed(2);
      susuan = '85920';
      rateAcc = '35%';
      return {tax:tax,susuan:susuan,rateAcc:rateAcc};
    }else{
      tax = (salary * 0.45 - 181920).toFixed(2);
      susuan = '181920';
      rateAcc = '45%';
    }
    return {tax:tax,susuan:susuan,rateAcc:rateAcc};
  },

  

  // 减除累计扣除
  calYingNaShuiAcc:function(){
    var yingNashuiEAcc = [];
    var salayAcc = this.calSalaryAcc();
    var gjjAcc = this.calGongjijinAcc();
    var sbAcc = this.calSBAcc();
    var person = this.calPersonAcc();
    var another = this.calAnotherAcc();
    var result = 0;
    console.log("专项附加扣除"+person);
    console.log("公积金累计"+gjjAcc);
    console.log("社保累计"+sbAcc);
    for(var i = 0;i < salayAcc.length;i++){
      // 累计扣除
      result = salayAcc[i] - (i + 1) * 5000 - gjjAcc[i] - sbAcc[i] - person[i] - another[i];
      if(result <= 0 || (i > 0 && (salayAcc[i] === salayAcc[i-1]))){
        result = 0
      }
      result = parseFloat(result).toFixed(2);
      yingNashuiEAcc.push(result);
    }
    this.setData({yingNashuiEAcc:yingNashuiEAcc});
  },

  calTaxAcc:function(){
    //获取应纳税额
    this.calYingNaShuiAcc();
    // var {tax,susuan,rateAcc} = {tax:0,susuan:'0',rateAcc:'0'}
    var taxAcc = this.data.taxAcc;
    var susuanAcc = this.data.susuanAcc;
    var rateAcc = this.data.rateAcc;
    var yingNa = this.data.yingNashuiEAcc;
    for(var i = 0;i < yingNa.length;i++){
      var obj = this.getRateAndKouchu(yingNa[i]);
      taxAcc.push(obj.tax);
      susuanAcc.push(obj.susuan);
      rateAcc.push(obj.rateAcc);
    }
    console.log("税额"+taxAcc)
    console.log("速算扣除"+susuanAcc)
    console.log("税率"+rateAcc)
    this.setData({taxAcc:taxAcc,susuanAcc:susuanAcc,rateAcc:rateAcc});
  },

  onBackToIndex(e){
    wx.navigateBack({
      delta: 1  // 返回上一级页面。
    });
  },
  /**
   * 生命周期函数--监听页面加载
   * //适用税率
   */
  onLoad(options){
    wx.showShareMenu({
      withShareTicket:true,
      menus:["shareAppMessage",'shareTimeline']});
    const mon = options.calDate;
    this.setData({calDate:mon});
    var length = Number(mon.slice(-2));
    var box = []
    for(var i = 1;i <= length;i++){
      box.push(i);
    }
    this.setData({monthBox:box});
    let that = this;
    try {
      //工资薪金
      var value = wx.getStorageSync('salary');
      if (value) {
        that.setData({salary:JSON.parse(value)});
      }
      value = wx.getStorageSync('salaryEnd');
      if (value) {
        that.setData({salaryEnd:JSON.parse(value)});
      }
      value = wx.getStorageSync('salaryStart');
      if (value) {
        that.setData({salaryStart:JSON.parse(value)});
      }
    // 社会保险
      value = wx.getStorageSync('sbStandard');
      if (value) {
        that.setData({sbStandard:JSON.parse(value)});
      }
      value = wx.getStorageSync('sbDaBingYL');
      if (value) {
        that.setData({sbDaBingYL:JSON.parse(value)});
      }
      value = wx.getStorageSync('sbIndex');
      if (value) {
        that.setData({sbIndex:JSON.parse(value)});
      }
      value = wx.getStorageSync('sbEndDate');
      if (value) {
        that.setData({sbEndDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('sbStartDate');
      if (value) {
        that.setData({sbStartDate:JSON.parse(value)});
      }

      //专项附加扣除
      value = wx.getStorageSync('eduDate');
      if(value){
        that.setData({eduDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('childEduRatio' );
      if(value){
      that.setData({childEduRatio:JSON.parse(value)});
      }
      value = wx.getStorageSync('furtherEduChoice' );
      if(value){
      that.setData({furtherEduChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('furtherEduDate');
      if(value){
      that.setData({furtherDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('degreeRuXueDate' );
      if(value){
      that.setData({degreeRuXueDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('degreeValue' );
      if(value){
      that.setData({degreeValue:JSON.parse(value)});
      }
      value = wx.getStorageSync('babyBirth' );
      if(value){
      that.setData({babyBirth:JSON.parse(value)});
      }
      value = wx.getStorageSync('babyCareRatio' );
      if(value){
      that.setData({babyCareRatio:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentStart' );
      if(value){
      that.setData({rentStart:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentEnd' );
      if(value){
      that.setData({rentEnd:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentType' );
      if(value){
      that.setData({rentType:JSON.parse(value)});
      }
      value = wx.getStorageSync('loanStartDate' );
      if(value){
      that.setData({loanStartDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('loanNum' );
      if(value){
      that.setData({loanNum:JSON.parse(value)});
      }
      value = wx.getStorageSync('elderDate' );
      if(value){
      that.setData({elderDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('elderValue');
      if(value){
      that.setData({elderValue:JSON.parse(value)});
      }
      value = wx.getStorageSync('furtherEduDate');
      if(value){
      that.setData({furtherEduDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('graduateDate' );
      if(value){
      that.setData({graduateDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('loanEndDate' );
      if(value){
      that.setData({loanEndDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('eduGraduateDate' );
      if(value){
      that.setData({eduGraduateDate:JSON.parse(value)});
      }

      // 公积金
      value = wx.getStorageSync('gjjStart');
      if(value){
        that.setData({gjjStart:JSON.parse(value)})
      }
      value = wx.getStorageSync('gjjEnd');
      if(value){
        that.setData({gjjEnd:JSON.parse(value)})
      }
      value = wx.getStorageSync('gjjStandard');
      if(value){
        that.setData({gjjStandard:JSON.parse(value)})
      }
      value = wx.getStorageSync('gjjIndex');
      if(value){
        that.setData({gjjIndex:JSON.parse(value)})
      }
      // 其他扣除
      value = wx.getStorageSync('anotherStart');
    if (value) {
      that.setData({anotherStart:JSON.parse(value)});
    }
    value = wx.getStorageSync('anotherEnd');
    if (value) {
      that.setData({anotherEnd:JSON.parse(value)});
    }
    value = wx.getStorageSync('nianJin');
    if (value) {
      that.setData({nianJin:JSON.parse(value)});
    }
    value = wx.getStorageSync('bussinessHealth');
    if (value) {
      that.setData({bussinessHealth:JSON.parse(value)});
    }
    value = wx.getStorageSync('yangLaoJin');
    if (value) {
      that.setData({yangLaoJin:JSON.parse(value)});
    }
    value = wx.getStorageSync('other');
    if (value) {
      that.setData({other:JSON.parse(value)});
    }

    } catch (e) {
      console.log(e)
      // Do something when catch error
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2
      })
    }
    var salaryAcc = this.data.salaryAcc;
    this.calTaxAcc();
    var cal = this.data.calDate;
    var idx = Number(cal.slice(-2));
    var taxMonth = '';
    var taxAcc = this.data.taxAcc;
    var susuan = this.data.susuanAcc;
    var rateAcc = this.data.rateAcc;
    var salaryAcc = this.data.salayAcc;
    var yingNa = this.data.yingNashuiEAcc;

    console.log("税额累计："+salaryAcc);
    console.log("应纳税额"+yingNa);

    if(salaryAcc.length === 0){
      this.setData({taxMonth:'0.00',susuanKouchu:'0.00',rate:'0.00'});
      return;
    }
    //把个税算出来
    if(idx === 1){
      var taxMonth = (taxAcc[0]).toString();
      // console.log(salaryAcc)
      this.setData({taxMonth:taxMonth,susuanKouchu:susuan[0],rate:rateAcc[0]});
      var salaryAfter = parseFloat(salaryAcc[0] - taxAcc[0]);
      if(salaryAfter < 0){
        var monthSal = salaryAcc[0].toString();
        this.setData({salaryAfter:monthSal});
      }
      this.setData({salaryAfter:salaryAfter.toString()});
      // this.setData({salaryAfter:"18976.78"});
      this.setData({LeijiYingNaShuiE:salaryAcc[0]});
    }
    else{
      // 当月累计交的税 - 上个月应该交的税 = 本月应交。
      if(taxAcc[idx - 1] === null || taxAcc[idx - 2] === null){
        this.setData({taxMonth:'0.00',susuanKouchu:'0.00',rate:'0.00'});
        return;
      }
      var temp1  = parseFloat(taxAcc[idx-1]);
      var temp2 = parseFloat(taxAcc[idx-2])
      var taxMonth = (temp1 - temp2).toFixed(2);
      if(taxMonth < 0){
        taxMonth = 0;
      }
      this.setData({taxMonth:taxMonth.toString(),susuanKouchu:susuan[idx - 1],rate:rateAcc[idx - 1]});
      var salCur = parseFloat(salaryAcc[idx - 1]);
      var salLast = parseFloat(salaryAcc[idx - 2])
      var salaryAfter = salCur - salLast - temp2;
      if(salaryAfter <= 0){
        var tempSal = (salCur - salLast).toString();
        console.log("本月工资"+tempSal)
        this.setData({salaryAfter:tempSal});
      }
      // this.setData({salaryAfter:salaryAfter.toString()});
      // var temp = (yingNa[idx - 1])
      var tempYingna = 0;
      for(var j = 0;j < yingNa.length;j++){
        if(parseFloat(yingNa[j]) > parseFloat(tempYingna)){
          tempYingna = yingNa[j];
        }
      }
      this.setData({LeijiYingNaShuiE:tempYingna});
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '答哥算税计算器',
      path: '/pages/index/index'
    }
  }
})